﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;

namespace Dtf.Core
{
    public class AppEngine
    {
        public AppEngine(Parameter param)
        {
            _param = param;
        }

        public Parameter Params
        {
            get
            {
                return _param;
            }
        }

        Parameter _param;
    }

    public class Parameter
    {
        public Parameter(string strParams)
        {
            _regex_param = new Regex("/(?<key>[^ ]+)[ ]*:[ ]*((?<value>[^ ]+)|(\"(?<value>[^.]+)\"))", RegexOptions.IgnoreCase);
            _dictParam = new Dictionary<string, string>();
            Match match = _regex_param.Match(strParams);
            while (match.Success)
            {
                string key = match.Result("${key}");
                string value = match.Result("${value}");
                if (!_dictParam.ContainsKey(key))
                {
                    _dictParam.Add(key, value);
                }
                match = match.NextMatch();
            }
        }

        public string this[string key]
        {
            get
            {

                string value;
                if (_dictParam.TryGetValue(key, out value))
                {
                    return value;
                }
                return null;
            }
        }

        private static Regex _regex_param;
        Dictionary<string, string> _dictParam;
    }
}
